import java.util.ArrayList;
import java.util.List;

public class Test4 {
    public static void main(String[] args) {
        ArrayList<User> List = new ArrayList<>();
        User u1 = new User("001","zhangsan","123456");
        User u2 = new User("002","lisi","12345678");
        User u3 = new User("003","wangwu","1346792580");
        List.add(u1);
        List.add(u2);
        List.add(u3);
        boolean flag = contains(List,"001");
        int Index = getIndex(List,"002");
        System.out.println(flag);
        System.out.println(Index);
    }

    public static boolean contains(ArrayList<User> List,String id){
//        boolean flag = false;
//        for (int i = 0; i < List.size(); i++) {
//            if (List.get(i).getId().equals(id)){
//                flag = true;
//                break;
//            }
//        }
//        return flag;
        if (getIndex(List,id)>=0){
            return true;
        }else{
            return false;
        }

    }




    public static int getIndex(ArrayList<User> List,String id){
        for (int i = 0; i < List.size(); i++) {
            if (List.get(i).getId().equals(id)){
                return i;
            }
        }
        return -1;
    }
}
